angular.service(ꞌvisibilityꞌ)   B
last analyzed

Complexity

Conditions 1
Paths 6

Size

Total Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 6
dl 0
loc 41
rs 8.8571
nop 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A ��) 0 11 4
A ��) 0 12 4
B ��) 0 14 5
1
/**
2
 visibility
3
 Service that holds all functions that determine which elements are visible.
4
5
 @namespace Services
6
 */
7
'use strict';
8
9
angular
10
  .module('game')
11
  .service('visibility', [
12
    function() {
13
      this.visible = function(items, func, currentElement, sortFunc, player) {
14
        let visibles = [];
15
        for (let i in items) {
16
          // if it is an array, we need to extract the item from the index
17
          let item = Array.isArray(items) ? items[i] : i;
18
          if (func(item, currentElement, player)) {
19
            visibles.push(item);
20
          }
21
        }
22
        if(sortFunc){
23
          visibles.sort(sortFunc);
24
        }
25
        return visibles;
26
      };
27
28
      this.isUpgradeVisible = function(name, slot, upgrade, player) {
29
        if (upgrade.tiers) {
30
          for (let tier of upgrade.tiers) {
31
            if (slot.generators[tier] === 0) {
32
              return false;
33
            }
34
          }
35
        }
36
        return meetDependencies(slot.upgrades, upgrade.deps) &&
37
          meetDependencies(player.exotic_upgrades[slot.element], upgrade.exotic_deps) &&
38
          meetDependencies(player.dark_upgrades, upgrade.dark_deps);
39
      };
40
41
      function meetDependencies(upgrades, dependencies) {
42
        if(!dependencies){
43
          return true;
44
        }
45
        for (let dep of dependencies) {
46
          if (!upgrades[dep]) {
47
            return false;
48
          }
49
        }
50
        return true;
51
      }
52
    }
53
  ]);
54